home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr48 / 386p_200.zip / CHARIO.ASM < prev    next >
Assembly Source File  |  1995-01-12  |  12KB  |  495 lines

  1. ; These routines use the screen dimensions specified in the chtil.inc file
  2.  
  3. ; WARNING! Some of this assembler code is highly interleaved to get the max
  4. ; from 486 and Pentium processors while running quite fast on good ol' 386.
  5. ; To better understand this code remember:
  6. ;           REGISTERS are used as variables whenever possible, so follow
  7. ;           what happens to every register.
  8. ;           Usually i interleave TWO sequences into one, skip one instruction
  9. ;           and you get the usual sequence everyone can understand.
  10. ;           I don't optimize sequences that clash with bottlenecks OUTSIDE
  11. ;           the processor (i.e. memory access), my main target is
  12. ;           to keep the most accessed stuff into registers
  13. ;           and process things at 32bit.
  14.  
  15.        .386P
  16. code32 segment para public use32
  17.        assume cs:code32,ds:code32
  18.        
  19. include 386power.inc       
  20. include 386video.inc
  21. include 386keyb.inc
  22. include 386file.inc
  23. include chtil.inc
  24.  
  25. ; MODULO Per I/O Character oriented
  26. ;
  27.         align dword
  28.         ; pointer to current character font bitmaps
  29.         public _CHRPAL,_CHRFNT,_CHRMENU1,_CHRMENU2
  30. _CHRPAL   dd 0
  31. _CHRFNT   dd 0
  32. _CHRMENU1 dd 0
  33. _CHRMENU2 dd 0
  34.         align byte
  35.  
  36.         public _LoadCharSet
  37. _LoadCharSet: ; in: in: esi= pointer to character bitmap file name
  38.               ; out: CARRY SET IF ERROR
  39.         pushad
  40.         ; allocate space for TWO character sets plus palette entries
  41.         ; load character font file
  42.         mov eax,_LoMemBase
  43.         mov _CHRPAL,eax
  44.         add eax,(12*3)
  45.         mov _CHRFNT,eax
  46.         mov _CHRMENU1,eax
  47.         add eax,CHARSIZE*128
  48.         mov _CHRMENU2,eax
  49.         call _LoFLoad
  50.         jc short LBye
  51.         cmp eax,((12*3)+(CHARSIZE*128))
  52.         jne short LBye
  53.         add _LoMemBase,eax        ; update memory base
  54.         mov ecx,(CHARSIZE*128)
  55.         mov esi,_CHRMENU1
  56.         mov edi,_CHRMENU2
  57.         add _LoMemBase,ecx       ; add space for the input character set
  58. transcol:
  59.         lodsb
  60.         cmp al,BRIGHT1_TEXT
  61.         jb nobri
  62.         cmp al,BRIGHT6_TEXT
  63.         jnbe nobri
  64.         add al,(DARK1_TEXT-BRIGHT1_TEXT)
  65.         jmp short guu
  66. nobri:  cmp al,DARK1_TEXT
  67.         jb guu
  68.         cmp al,DARK6_TEXT
  69.         jnbe guu
  70.         add al,(BRIGHT1_TEXT-DARK1_TEXT)
  71. guu:    stosb
  72.         dec ecx
  73.         jne transcol
  74.         ; now change palette
  75.  
  76.         mov esi,_CHRPAL ; get pointer to character's private palette entries
  77.  
  78.         ; bright
  79.         mov al,BRIGHT1_TEXT
  80. palettb:
  81.         mov edx,[esi]
  82.         add esi,3
  83.         and edx,00FFFFFFh
  84.         call _Set1Pal
  85.         inc al
  86.         cmp al,BRIGHT6_TEXT
  87.         jbe palettb
  88.  
  89.         ; dark
  90.         mov al,DARK1_TEXT
  91. palettd:
  92.         mov edx,[esi]
  93.         add esi,3
  94.         and edx,00FFFFFFh
  95.         call _Set1Pal
  96.         inc al
  97.         cmp al,DARK6_TEXT
  98.         jbe palettd
  99.         popad
  100.         clc
  101.         ret
  102. LBye:   popad
  103.         stc
  104.         ret
  105.  
  106. SPUTS macro
  107.         movsd
  108.         movsd
  109.         add edi,((RXWIDTH+XBORDER)-8)
  110.         endm
  111.  
  112.         public _PutString
  113.  
  114. _PutString:
  115.          ; edi = screen base
  116.          ; eax = x in pixels
  117.          ; edx = y in pixels
  118.          ; ebx = string
  119.          
  120.          pushad
  121.          add edi,eax
  122.          mov ebp,_CHRFNT
  123.          add edi,[edx*4+_RowStart]
  124.          jmp @czero
  125. @bliit:  inc ebx
  126.          shl esi,CHARSHIFT
  127.          add esi,ebp
  128. LUPPALO:         
  129.          SPUTS
  130.          SPUTS
  131.          SPUTS
  132.          SPUTS
  133.          SPUTS
  134.          SPUTS
  135.          SPUTS
  136.          movsd
  137.          movsd
  138.          sub edi,((RXWIDTH+XBORDER)*7)
  139. @czero:         
  140.          movsx esi,byte ptr [ebx]
  141.          cmp esi,0
  142.          jne @bliit
  143.          
  144.          popad
  145.      ret
  146.  
  147.  
  148.  
  149.         public _PutHex
  150.  
  151. _PutHex: ; scrive il numero esadecimale ( oppure bcd) a 32 bit
  152.          ; contenuto in ebx
  153.          ; edi = screen dest
  154.          ; eax = x in pixels
  155.          ; edx = y in pixels
  156.          ; ecx = digits to use
  157.          ; ebx = number to write
  158.          pushad
  159.          add edi,eax
  160.          shl ecx,3
  161.          add edi,[edx*4+_RowStart]
  162.          add edi,ecx
  163.          mov esi,ebx
  164.          shr ecx,3
  165.          mov ebp,_CHRFNT
  166.          sub edi,8
  167. @ngnchar:
  168.          and esi,0Fh
  169.          shr ebx,4
  170.          cmp esi,10
  171.          jb  @isdec
  172.          add esi,(65-48-10) ; 'A' - '0' - 10
  173. @isdec:   
  174.          add esi,48 ; '0' == 48
  175.          shl esi,CHARSHIFT
  176.          add esi,ebp
  177. SLUPPALO:         
  178.          SPUTS
  179.          SPUTS
  180.          SPUTS
  181.          SPUTS
  182.          SPUTS
  183.          SPUTS
  184.          SPUTS
  185.          movsd
  186.          movsd
  187.          sub edi,((RXWIDTH+XBORDER)*7)+8+8
  188.          mov esi,ebx
  189.          dec ecx
  190.          jnz @ngnchar
  191.          popad
  192.      ret
  193.  
  194.  
  195.         public _PutInt
  196.  
  197. _PutInt: ; scrive l' integer a 32 bit contenuto in ebx
  198.          ; edi = screen dest
  199.          ; eax = x in pixels
  200.          ; edx = y in pixels
  201.          ; ecx = digits to use
  202.          ; ebx = number to write
  203.          pushad
  204.          cmp ebx,0
  205.          jge think_positive
  206.          push offset put_dash
  207.          neg ebx
  208.          dec ecx   ; one position is for the '-' sign
  209.          add eax,8 ; one character position forward
  210.          jmp short think_this
  211.  
  212. put_dash:
  213.          mov esi,('-' shl CHARSHIFT)
  214.          mov edx,7
  215.          add esi,ebp
  216. dashloop:
  217.          SPUTS
  218.          dec edx
  219.          jne dashloop
  220.          movsd
  221.          movsd
  222.          sub edi,((RXWIDTH+XBORDER)*7)+8+8
  223.          or ecx,ecx
  224.          jnz zappzero
  225.          popad
  226.          ret
  227.  
  228.         public _PutUnsigned
  229.  
  230. _PutUnsigned: ; scrive il numero positivo a 32 bit contenuto in ebx
  231.          ; edi = screen dest
  232.          ; eax = x in pixels
  233.          ; edx = y in pixels
  234.          ; ecx = digits to use
  235.          ; ebx = number to write
  236.          pushad
  237. think_positive:
  238.          push offset no_minus
  239. think_this:
  240.          add edi,eax
  241.          shl ecx,3 ; ecx*8
  242.          add edi,[edx*4+_RowStart]
  243.          add edi,ecx ; move to last digit
  244.          mov eax,ebx
  245.          shr ecx,3
  246.          mov ebp,_CHRFNT
  247.          sub edi,8
  248.          mov ebx,10
  249. @ungnchar:
  250.          xor edx,edx
  251.          div ebx
  252.          add edx,'0' ; '0' == 48
  253.          shl edx,CHARSHIFT
  254.          lea esi,[edx+ebp]
  255.          SPUTS
  256.          SPUTS
  257.          SPUTS
  258.          SPUTS
  259.          SPUTS
  260.          SPUTS
  261.          SPUTS
  262.          movsd
  263.          movsd
  264.          sub edi,((RXWIDTH+XBORDER)*7)+8+8
  265.          or  eax,eax
  266.          jz  goon
  267.          dec ecx
  268.          jnz @ungnchar
  269.          ret
  270. goon:    dec ecx
  271.          ret
  272. zappzero:
  273.          add ebp,(' ' shl CHARSHIFT)
  274. tzappzero:
  275.          mov edx,7
  276.          mov esi,ebp
  277. spcloop:
  278.          SPUTS
  279.          dec edx
  280.          jnz spcloop
  281.          movsd
  282.          movsd
  283.          sub edi,((RXWIDTH+XBORDER)*7)+8+8
  284.          dec ecx
  285.          jnz tzappzero
  286.          popad
  287.          ret
  288.  
  289. no_minus:
  290.          test ecx,ecx
  291.          jnz zappzero
  292.          popad
  293.          ret
  294.          
  295.          public _GetString
  296. _GetString:
  297.         ; edi= scr dest
  298.         ; eax= x in pixels
  299.         ; edx= y in pixels
  300.         ; ecx= max. string size excluding terminal NUL
  301.         ; ebx= string
  302.         pushad
  303.         mov checksign,0
  304.         mov min_ch,1   ; the NUL symbol is not supported
  305.         mov max_ch,126 ; the "cursor"  symbol is not supported
  306.         call stringy
  307.         popad
  308.         ret
  309.  
  310. stgzero db 'CHARIO: Attempt to read chars on a zero lenght string',CR,LF,'$'
  311. chvai:
  312.         mov _386Return,offset stgzero
  313.         jmp _Exit
  314.  
  315. stringy:
  316.         call _KeybAsciiMode
  317.         mov ebp,0
  318.         or ecx,ecx
  319.         jz chvai
  320.         pushad                 ; fill stringz with space characters
  321.         mov al,32 ; space      ;
  322.         mov edi,ebx            ;
  323.         ; ecx already loaded   ;
  324.         rep stosb              ;
  325.         mov byte ptr [edi],0   ;
  326.         popad                  ;
  327.         
  328.         mov byte ptr [ebx],127 ; put cursor char
  329.         call _PutString
  330.         call _PageFlip0
  331. showit:        
  332.         push eax
  333. retry:        
  334.         call _ReadAscii
  335.         cmp al,8 ;BACKSPACE?
  336.         jne nodel
  337.         cmp ebp,ecx
  338.         jae no_xspc
  339.         mov byte ptr [ebx+ebp],32
  340. no_xspc:
  341.         cmp ebp,0
  342.         je zerobuf
  343.         dec ebp
  344. zerobuf:        
  345.         mov byte ptr [ebx+ebp],127 ; new cursor position
  346.         jmp short nukey
  347. nodel:  cmp al,13 ;ENTER?
  348.         je gotstring
  349.         cmp ebp,ecx
  350.         jae retry
  351.         cmp checksign,0
  352.         je nosign
  353.         or ebp,ebp ; you can put a '-' as first char
  354.         jnz nosign
  355.         cmp al,'-'
  356.         je gudkey
  357. nosign:
  358.         cmp al,min_ch
  359.         jb retry
  360.         cmp al,max_ch
  361.         ja retry
  362. gudkey:
  363.         mov [ebx+ebp],al
  364.         inc ebp
  365.         cmp ebp,ecx
  366.         jae nukey
  367.         mov byte ptr [ebx+ebp],127 ; put cursor char
  368. nukey:
  369.         pop eax
  370.         call _PutString
  371.         pushad
  372.         mov ecx,ebp
  373.         sub eax,_VDispX
  374.         inc ecx
  375.         sub edx,_VDispY
  376.         mov ebx,8
  377.         shl ecx,1   ; get nudget count
  378.         call _TouchBlock
  379.         call _PageFlip1
  380.         popad
  381.         jmp short showit
  382. gotstring:
  383.         pop eax
  384.         mov byte ptr [ebx+ebp],0
  385.         call _KeybRawMode
  386.         ret
  387.  
  388. unstring  db 12 dup(0)
  389. checksign db 0
  390. max_ch    db 0
  391. min_ch    db 0
  392. align dword
  393. got_this  dd 0
  394. align byte
  395.  
  396.         public _GetInt
  397. _GetInt:
  398.         ; in:
  399.         ; edi= scr dest
  400.         ; eax= x in pixels
  401.         ; edx= y in pixels
  402.         ; ecx= max. digits (there is a practical limit of 10 digits)
  403.         ; out:
  404.         ; ebx= returned value
  405.         pushad
  406.         mov checksign,1
  407.         mov min_ch,'0'
  408.         mov max_ch,'9'
  409.         cmp ecx,11
  410.         jb  utype_it
  411.         mov ecx,11
  412.         jmp short utype_it
  413.  
  414.         public _GetUnsigned
  415. _GetUnsigned:
  416.         ; in:
  417.         ; edi= scr dest
  418.         ; eax= x in pixels
  419.         ; edx= y in pixels
  420.         ; ecx= max. digits (there is a practical limit of 10 digits)
  421.         ; out:
  422.         ; ebx= returned value
  423.         pushad
  424.         mov checksign,0
  425.         mov min_ch,'0'
  426.         mov max_ch,'9'
  427.         cmp ecx,10
  428.         jb  utype_it
  429.         mov ecx,10
  430. utype_it:
  431.         mov ebx,offset unstring
  432.         call stringy
  433.  
  434.         ; now execute conversion
  435.         cmp checksign,0
  436.         jnz siign
  437.  
  438.         ; unsigned dword
  439.         cmp ebp,10
  440.         jb small_enough
  441.         cmp byte ptr [ebx],'4' ; no more than 3999999999
  442.         jb small_enough
  443.         jmp short utype_it
  444.  
  445.         ; signed dword
  446. siign:  cmp ebp,11
  447.         jb  maybe_small
  448.         cmp byte ptr [ebx],'-'
  449.         jne utype_it  ; heck! 11 chars and no sign, it can't fit!!!
  450.         ; maybe it can fit
  451.         cmp byte ptr [ebx+1],'2'
  452.         jnb utype_it  ; no more than +/-1999999999
  453.         jmp short dash_ahead
  454.  
  455. maybe_small:
  456.         cmp byte ptr [ebx],'-'
  457.         je dash_ahead  ; max. 10 chars and sign, it can fit
  458.         ; 10 chars with no sign, check head digit
  459.         mov checksign,0 ; sign was not present
  460.         cmp ebp,10
  461.         jb small_enough
  462.         cmp byte ptr [ebx+1],'2'
  463.         jnb utype_it  ; no more than +/-1999999999
  464.         jmp short small_enough
  465. dash_ahead:
  466.         inc ebx  ;
  467.         dec ebp  ; cut out sign
  468. small_enough:
  469.         xor eax,eax
  470.         or ebp,ebp  ; zero digits ?
  471.         je udid     ;
  472. accumulate:
  473.         mov edx,10
  474.         movzx edi,byte ptr [ebx]
  475.         inc ebx
  476.         or edi,edi ; reached the final NUL ?
  477.         je udid  ;
  478.         sub edi,'0'
  479.         mul edx
  480.         add eax,edi
  481.         jmp short accumulate
  482. udid:   mov got_this,eax
  483.         popad
  484.         mov ebx,got_this
  485.         cmp checksign,0
  486.         je no_neg
  487.         neg ebx
  488. no_neg:
  489.         ret
  490.  
  491. code32 ends
  492.  
  493.  END
  494.  
  495.